package com.taotie.mapper;

import com.github.pagehelper.Page;
import com.taotie.dto.GoodsSalesDTO;
import com.taotie.dto.OrdersPageQueryDTO;
import com.taotie.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    void insert(Orders order);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据订单id查询订单信息
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    /**
     * 根据状态查询订单数量
     * @param status
     * @return
     */
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);

    /**
     * 商家接单，将数据库status改为3
     * @param id
     */
    @Update("update orders set status = 3 where id = #{id}")
    void confirm(Long id);

    /**
     * 商家派送，将status改为4
     * @param id
     */
    @Update("update orders set status = 4 where id = #{id}")
    void delivery(Long id);

    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
  List<Orders> getByStatusAndOrderTime(Integer status, LocalDateTime orderTime);

    /**
     * 查询营业额
     * @param map
     * @return
     */
    Double sumByMap(Map<Object, Object> map);

    Integer countByMap(Map<Object, Object> map);

    List<GoodsSalesDTO> getSalesTop10(LocalDateTime beginTime, LocalDateTime endTime);
}
